/*
 * Copyright 2012 Gregor Schauer
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package at.schauer.gregor.vienna.context;

import at.schauer.gregor.vienna.convert.provider.ConverterProvider;
import at.schauer.gregor.vienna.datastore.DataStore;
import at.schauer.gregor.vienna.identifier.IdentifierGenerator;
import at.schauer.gregor.vienna.metadata.MetadataProvider;
import at.schauer.gregor.vienna.serializer.Serializer;
import at.schauer.gregor.vienna.util.ViennaUtils;

import java.util.*;

/**
 * @author Gregor Schauer
 */
public class DefaultViennaContext implements ViennaContext {
	protected Map<Class<?>, ConverterProvider<?>> converterProviderMap = new LinkedHashMap<Class<?>, ConverterProvider<?>>();
	protected Map<Class<?>, Serializer<?>> serializerMap = new HashMap<Class<?>, Serializer<?>>();
	protected Map<Class<?>, MetadataProvider<?>> metadataProviderMap = new HashMap<Class<?>, MetadataProvider<?>>();
	protected Map<Class<?>, DataStore<?>> dataStoreMap = new HashMap<Class<?>, DataStore<?>>();
	protected Map<Class<?>, IdentifierGenerator<?, ?>> identifierGeneratorMap = new HashMap<Class<?>, IdentifierGenerator<?, ?>>();

	@Override
	@SuppressWarnings("unchecked")
	public <T> ConverterProvider<T> getConverterProvider(Class<T> type) {
		return (ConverterProvider<T>) ViennaUtils.filter(converterProviderMap, type);
	}

	@Override
	@SuppressWarnings("unchecked")
	public <T> Serializer<T> getSerializer(Class<T> type) {
		return (Serializer<T>) ViennaUtils.filter(serializerMap, type);
	}

	@Override
	@SuppressWarnings("unchecked")
	public <T> MetadataProvider<T> getMetadataProvider(Class<T> type) {
		return (MetadataProvider<T>) ViennaUtils.filter(metadataProviderMap, type);
	}

	@Override
	@SuppressWarnings("unchecked")
	public <T> DataStore<T> getDataStore(Class<T> type) {
		return (DataStore<T>) ViennaUtils.filter(dataStoreMap, type);
	}

	@Override
	@SuppressWarnings("unchecked")
	public <I, T> IdentifierGenerator<I, T> getIdentifierGenerator(Class<T> type) {
		return (IdentifierGenerator<I, T>) ViennaUtils.filter(identifierGeneratorMap, type);
	}

	public Map<Class<?>, ConverterProvider<?>> getConverterProviderMap() {
		return converterProviderMap;
	}

	public void setConverterProviderMap(Map<Class<?>, ConverterProvider<?>> converterProviderMap) {
		this.converterProviderMap = converterProviderMap;
	}

	public Map<Class<?>, Serializer<?>> getSerializerMap() {
		return serializerMap;
	}

	public void setSerializerMap(Map<Class<?>, Serializer<?>> serializerMap) {
		this.serializerMap = serializerMap;
	}

	public Map<Class<?>, MetadataProvider<?>> getMetadataProviderMap() {
		return metadataProviderMap;
	}

	public void setMetadataProviderMap(Map<Class<?>, MetadataProvider<?>> metadataProviderMap) {
		this.metadataProviderMap = metadataProviderMap;
	}

	public Map<Class<?>, DataStore<?>> getDataStoreMap() {
		return dataStoreMap;
	}

	public void setDataStoreMap(Map<Class<?>, DataStore<?>> dataStoreMap) {
		this.dataStoreMap = dataStoreMap;
	}

	public Map<Class<?>, IdentifierGenerator<?, ?>> getIdentifierGeneratorMap() {
		return identifierGeneratorMap;
	}

	public void setIdentifierGeneratorMap(Map<Class<?>, IdentifierGenerator<?, ?>> identifierGeneratorMap) {
		this.identifierGeneratorMap = identifierGeneratorMap;
	}
}
